package org.redis.cluster.config;

import org.redis.cluster.RedisCluster;
import org.redis.cluster.extension.ExtensionLoader;
import org.redis.cluster.plugin.Plugin;
import org.redis.cluster.util.Assert;

public class DefaultConfigManagerFactory implements ConfigManagerFactory,Plugin {

	private RedisCluster redisCluster;
	private ExtensionLoader extensionLoader;
	
	@Override
	public void init(RedisCluster redisCluster) {
		this.redisCluster=redisCluster;
		this.extensionLoader=redisCluster.getExtensionLoader();
	}
	
	@Override
	public void destroy() {
	}
	
	@Override
	public ConfigManager getConfigManager() {
		ConfigLoader configLoader=initConfigLoader();
		
		ServerConfig serverConfig=configLoader.loadServerConfig();
		RegistryConfig registryConfig=configLoader.loadRegistryConfig();
		SystemConfig systemConfig=configLoader.loadSystemConfig();
		
		Assert.notNull(serverConfig,"serverConfig解析错误");
		Assert.notNull(registryConfig,"registryConfig解析错误");
		
		return new DefaultConfigManager(serverConfig, registryConfig, systemConfig);
	}

	protected ConfigLoader initConfigLoader() {
		return new XmlConfigLoader();
	}
}